package fcrpt

import com.tsqc.system.util.table.TranposUtils

class ProcessLineController {
    def dynamicQueryService
    def processLine(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def tableHeadList=[]
        def processLine=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0
        params.SYS_QUERY_NAME = 'processState'
        def stateList = dynamicQueryService.queryForList(params)
        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'processLine'
            processLine = dynamicQueryService.queryForList(params)
            if (processLine.size() > 0) {
                tableHeadList = processLine[0].keySet()
            }
            params.SYS_QUERY_NAME = 'processLineCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT


        }
        print(tableHeadList)
        [startno:params.startno?:'',
         endno:params.endno?:'',
         pageSize:pageSize,
         totalCount: totalCount,
         pageSizeList: pageSizeList,
         tableHeadList:tableHeadList,
         processLine:processLine,
         stateList:stateList,
         startTime:params.startTime?:'',
         endTime:params.endTime?:'',
         partName:params.partName?:'',
         processCode:params.processCode?:'',
         group3:params.group3?:'',
         partDesc:params.partDesc?:'',
         state:params.state?:'',
         createdBy:params.createdBy?:'',
         approvedBy:params.approvedBy?:''
        ]
    }


    def processLineStep(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        def pageSizeList = [10,20,50,100]
        params.SYS_QUERY_NAME = 'processLineStep'
        def processLineStep = dynamicQueryService.queryForList(params)
        def list=TranposUtils.colToRow('SEQ_NO','STEP_DESC',processLineStep)
        def tableHeadList=[]
        def totalCount=0
        if (list.size() > 0) {
            tableHeadList = list[0].keySet()

        }else{
            totalCount =0
        }

        [startno:params.startno,endno:params.endno,pageSize     : pageSize, totalCount: totalCount, pageSizeList: pageSizeList,pageCurrent:pageCurrent,
         tableHeadList:tableHeadList,processLineStep:processLineStep,list:list]
    }
}
